package cn.jy.ad.controller;

import cn.jy.ad.common.Result;
import cn.jy.ad.service.AppAdsService;
import cn.jy.common.ad.domain.ExpressAppAds;
import cn.jy.common.ad.domain.dto.ExpressAppAdsDto;
import cn.jy.common.ad.domain.vo.ExpressSplitAdvertisingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/app")
public class AppAdsController {
    @Autowired
    private AppAdsService appAdsService;

    @PostMapping("/list")
    public Result list(@RequestBody ExpressSplitAdvertisingVo vo) {
      vo.setOffset((vo.getPageNum() - 1) * vo.getPageSize());
      List<ExpressAppAdsDto> list = appAdsService.list(vo);
        Long count =Long.valueOf(appAdsService.count(vo));
        return Result.publicSuccess(count,list);
    }
    @PostMapping("/updateStatus")
    public Result updateStatus(@RequestBody ExpressAppAds expressAppAds) {
        appAdsService.updateStatus(expressAppAds);
        return Result.success();
    }
    @PostMapping("/addAppAds")
    public Result addAppAds(@RequestBody ExpressAppAds expressAppAds) {
        appAdsService.addAppAds(expressAppAds);
        return Result.success();
    }
    @PostMapping("/updateAppAds")
    public Result updateAppAds(@RequestBody ExpressAppAds expressAppAds) {
        appAdsService.updateAppAds(expressAppAds);
        return Result.success();
    }
    @GetMapping("/selectAppAdById/{id}")
    public Result selectAppAdById(@PathVariable("id") Integer id) {
        ExpressAppAds expressAppAds = appAdsService.selectAppAdById(id);
        return Result.success(expressAppAds);
    }


}
